from .config import config

# 数据库名
MYSQL_NAME = config.mysql.database.default
# 数据库IP
MYSQL_HOST = config.mysql.host
# 数据库端口
MYSQL_PORT = config.mysql.port
# 数据库密码
MYSQL_PASSWORD = config.mysql.password
# 数据库用户
MYSQL_USER = config.mysql.user


# 获取数据库配置
DATABASES = {
    "default": {
        # "ENGINE": "django.db.backends.mysql",
        "ENGINE": "dj_db_conn_pool.backends.mysql",
        "NAME": MYSQL_NAME,
        "USER": MYSQL_USER,
        "PASSWORD": MYSQL_PASSWORD,
        "HOST": MYSQL_HOST,
        "PORT": MYSQL_PORT,
        "ATOMIC_REQUESTS": True,
        "CHARSET": "utf8",
        "COLLATION": "utf8_bin",
        # django-db-connection-pool 配置参数
        "POOL_OPTIONS": {
            "POOL_SIZE": 10,  # 基础连接量
            "MAX_OVERFLOW": 15,  # 最大允许溢出
            "RECYCLE": 1 * 60 * 60,  # 闲置的连接回收时间
            "TIMEOUT": 30,  # 获取连接超时时间
            "PRE_PING": True,  # 启用连接前检查（关键配置）
        },
    }
}


"""
# settings.py下
from base_config.mysql_config import DATABASES
DATABASES = DATABASES
"""
